/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2023/2/28 9:11
 * @Version 1.0
 */
package com.eight.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eight.dao.CarCommentDao;
import com.eight.feign.CarCommentFeign;
import com.eight.pojo.TbCarComment;
import com.eight.pojo.TbUser;
import com.eight.service.CarCommentService;
import com.eight.vo.CarVo;
import com.eight.vo.ComResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.OutputStream;
import java.util.List;

@Service
@SuppressWarnings("all")
public class CarCommentServiceImpl implements CarCommentService {

    @Autowired
    private CarCommentDao carCommentDao;
    @Autowired
    private CarCommentFeign carCommentFeign;

    @Override
    public ComResult selectComment(CarVo carVo) {
        Page<Object> page = PageHelper.startPage(carVo.getPageNum(), carVo.getPageSize());
        List<TbCarComment> tbCarComments=null;
        if (carVo.getName() != null) {
            TbUser tbUser = carCommentFeign.selectUserFindUsername(carVo.getName());
            tbCarComments = carCommentDao.selectComment(tbUser.getId());
        }else {
            tbCarComments = carCommentDao.selectComment(null);
        }
        PageInfo<TbCarComment> info=new PageInfo<>(tbCarComments);
        System.out.println(info);
        return new ComResult(2000,"查询成功",info);
    }

    @Override
    public ComResult insertComment(TbCarComment tbCarComment) {
        int insert = carCommentDao.insert(tbCarComment);
        return new ComResult(2000,"添加评论成功",insert);
    }

    @Override
    public ComResult deleteComment(int id) {
        int delete = carCommentDao.deleteById(id);
        return new ComResult(2000,"删除评论成功",delete);
    }

    @Override
    public ComResult updateComment(TbCarComment tbCarComment) {
        int update = carCommentDao.updateById(tbCarComment);
        return new ComResult(2000,"修改评论成功",update);
    }

    @Override
    public ComResult selectContent(TbCarComment tbCarComment) {
        List<TbCarComment> listContent = carCommentDao.listContent(tbCarComment);
        return new ComResult(2000,"查询成功",listContent);
    }


}

